package cn.com.gas.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.stereotype.Controller;

import cn.com.common.constants.Constants;
import cn.com.common.result.DataResult;
import cn.com.gas.constants.GasConstants;
import cn.com.gas.entity.GasAnalyseRegionRankingEntity;
import cn.com.gas.entity.GasDeclaretaxEntity;
import cn.com.gas.entity.GasOilpriceEntity;
import cn.com.gas.entity.GasStationinfoEntity;
import cn.com.gas.entity.GasStaytimeResultEntity;
import cn.com.gas.service.GasAnalyseRegionRankingService;
import cn.com.gas.service.GasDeclaretaxService;
import cn.com.gas.service.GasOilpriceService;
import cn.com.gas.service.GasStationinfoService;
import cn.com.gas.service.GasStaytimeResultService;
import cn.com.system.service.impl.HttpSessionService;
import cn.com.util.TsBqUtils;
import io.swagger.annotations.ApiOperation;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 首页
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-03-24 01:14:06
 */
@Controller
@RequestMapping("/gas/homemain")
public class GasHomeMainController {
	@Autowired
	private GasStaytimeResultService gasStaytimeResultService;
	
	@Autowired
	private GasDeclaretaxService gasDeclaretaxService;
	@Autowired
	private GasStationinfoService gasStationinfoService;
	@Autowired
	private GasOilpriceService gasOilpriceService;
	
	@Autowired
	private GasAnalyseRegionRankingService gasAnalyseRegionRankingService;
	
	@Autowired
	private HttpSessionService httpSessionService;
	
	
	@ApiOperation(value = "首页h2标签数据")
	@PostMapping("/h2data")
	// @RequiresPermissions("gasStaytimeResult:list")
	@ResponseBody
	public DataResult h2data() {
		
		String currentDeptId = httpSessionService.getCurrentDeptId();
		
		List<Object> list = new ArrayList<>();
		
		
		LambdaQueryWrapper<GasStationinfoEntity> queryWrapper1 = Wrappers.lambdaQuery();
		// queryWrapper1.eq(GasStationinfoEntity::getPid, "5c8baa4b-081f-41aa-a549-2235b786c7c7");
		// queryWrapper1.eq(GasStationinfoEntity::getType, "group");
		// queryWrapper1.eq(GasStationinfoEntity::getIsAnalyse, "Y");

		// 查询加油站
		String taxOrgLevel = TsBqUtils.getTaxOrgLevel(currentDeptId);
		if(Constants.TAX_COUNTES.equals(taxOrgLevel)){
			// 县区局
			queryWrapper1.eq(GasStationinfoEntity::getType, "group");
			queryWrapper1.eq(GasStationinfoEntity::getIsAnalyse, "Y");
			queryWrapper1.eq(GasStationinfoEntity::getTaxorgcode, currentDeptId);
			
		}else if(Constants.TAX_CITIES.equals(taxOrgLevel)){
			// 市局
			queryWrapper1.eq(GasStationinfoEntity::getType, "group");
			queryWrapper1.eq(GasStationinfoEntity::getIsAnalyse, "Y");
			queryWrapper1.like(GasStationinfoEntity::getTaxorgcode, currentDeptId.substring(0,5));
		}else {
			// 省局
			queryWrapper1.eq(GasStationinfoEntity::getType, "group");
			queryWrapper1.eq(GasStationinfoEntity::getIsAnalyse, "Y");
		}
		
		
		// int count1 = gasStationinfoService.count(queryWrapper1);
		List<GasStationinfoEntity> listStationinfo = gasStationinfoService.list(queryWrapper1);
		list.add(listStationinfo.size()); // 1 加油站
		
		
		list.add("*"); // 2 本月金额
		
		LambdaQueryWrapper<GasOilpriceEntity> queryWrapper3 = Wrappers.lambdaQuery();
		queryWrapper3.orderByDesc(GasOilpriceEntity::getCreateTime);
		GasOilpriceEntity gasOilpriceEntity = gasOilpriceService.getOne(queryWrapper3);
		if(TsBqUtils.isNotNull(gasOilpriceEntity)){
			list.add(gasOilpriceEntity.getGasoline()); // 3 汽油
			list.add(gasOilpriceEntity.getDiesel()); // 4 柴油
		}else{
			list.add("*"); // 3 汽油
			list.add("*"); // 4 柴油
		}
		
		
		// LambdaQueryWrapper<GasServerAreaEntity> queryWrapper5 = Wrappers.lambdaQuery();
		// LambdaQueryWrapper<GasServerAreaEntity> queryWrapper5 = new LambdaQueryWrapper<>();
		// queryWrapper5.select
		
		List<String> stationinfoIds = new ArrayList<>();
		
		for (GasStationinfoEntity gasStationinfoEntity : listStationinfo) {
			String id = gasStationinfoEntity.getId();
			stationinfoIds.add(id);
		}
		
		LambdaQueryWrapper<GasStationinfoEntity> queryWrapperCamOff = Wrappers.lambdaQuery();
		queryWrapperCamOff.in(GasStationinfoEntity::getPid, stationinfoIds);
		queryWrapperCamOff.eq(GasStationinfoEntity::getType, "cam");
		queryWrapperCamOff.eq(GasStationinfoEntity::getIconSkin, GasConstants.ICON_SKIN_OFF);// 离线
		List<GasStationinfoEntity> camOff = gasStationinfoService.list(queryWrapperCamOff);
		
		
		LambdaQueryWrapper<GasStationinfoEntity> queryWrapperCamOn = Wrappers.lambdaQuery();
		queryWrapperCamOn.in(GasStationinfoEntity::getPid, stationinfoIds);
		queryWrapperCamOn.eq(GasStationinfoEntity::getType, "cam");
		queryWrapperCamOn.eq(GasStationinfoEntity::getIconSkin, GasConstants.ICON_SKIN_ON);// 在线
		List<GasStationinfoEntity> camOn = gasStationinfoService.list(queryWrapperCamOn);
		
		// QueryWrapper<GasServerAreaEntity> queryWrapper5 = new QueryWrapper<>();
		
		// queryWrapper5.select("DISTINCT camid").lambda();
		
		// List<GasServerAreaEntity> camidList = gasServerAreaService.list(queryWrapper5);
		
		// int count5 = stationinfoIds.size();
		
		list.add(camOff.size() + camOn.size()); // 5 所有摄像头
		
		
		list.add(camOn.size()); // 6 在线摄像头

		list.add("*"); // 7 本月油量
		list.add("*"); // 8 今日油价
		
		list.add(gasOilpriceEntity.getNinetyEight()); // 9 98号
		list.add(gasOilpriceEntity.getZero()); // 10 0号
		
		list.add(camOff.size()); // 11 异常摄像头
		
		
		/*LambdaQueryWrapper<GasForecastEntity> queryWrapper12 = Wrappers.lambdaQuery();
		queryWrapper12.orderByDesc(GasForecastEntity::getCreateTime);
		GasForecastEntity gasForecastEntity = gasForecastService.getOne(queryWrapper12);
		if(TsBqUtils.isNotNull(gasForecastEntity)){
			list.add(gasForecastEntity.getNumerical()); // 12 预估值
		}else{
			list.add("*");
		}*/
		LocalDate now = LocalDate.now();
		int year = now.getYear(); // 获取当前年份
		int month = now.getMonthValue(); // 获取当前月份
		String monthYear = handleMonthYear(month,year);
		
		LambdaQueryWrapper<GasAnalyseRegionRankingEntity> queryWrapper12 = Wrappers.lambdaQuery();
		if(Constants.TAX_COUNTES.equals(taxOrgLevel)){
			// 县区局
			queryWrapper12.eq(GasAnalyseRegionRankingEntity::getTaxorgcode, currentDeptId);
		}else if(Constants.TAX_CITIES.equals(taxOrgLevel)){
			// 市局
			queryWrapper12.like(GasAnalyseRegionRankingEntity::getTaxorgcode, currentDeptId.substring(0,5));
		}else {
			// 省局
			
		}
		queryWrapper12.eq(GasAnalyseRegionRankingEntity::getYearMonths, monthYear);
		
		List<GasAnalyseRegionRankingEntity> analyseRegionRankingList = gasAnalyseRegionRankingService.list(queryWrapper12);
		if(TsBqUtils.isNotNull(analyseRegionRankingList)){
			BigDecimal sale = new BigDecimal("0.00");
			for (GasAnalyseRegionRankingEntity analyseRegionRanking : analyseRegionRankingList) {
				sale = sale.add(new BigDecimal(analyseRegionRanking.getSale()));
			}
			list.add(sale);
		}else{
			list.add("0.00");
		}
		
		
		
		
		return DataResult.success(list);

	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@ApiOperation(value = "获取停留时间TOP数据")
	@PostMapping("/staytimeTop")
	@ResponseBody
	public DataResult staytimeTop(@RequestBody GasStaytimeResultEntity gasStaytimeResult) throws ParseException {
		String currentDeptId = httpSessionService.getCurrentDeptId();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		// 查询加油站
		LambdaQueryWrapper<GasStationinfoEntity> queryWrapperStationinfo = Wrappers.lambdaQuery();
		// queryWrapperStationinfo.eq(GasStationinfoEntity::getPid, "5c8baa4b-081f-41aa-a549-2235b786c7c7"); //  信都区
		// queryWrapperStationinfo.eq(GasStationinfoEntity::getType, "group");
		// queryWrapperStationinfo.eq(GasStationinfoEntity::getIsAnalyse, "Y");
		
		
		if(Constants.TAX_COUNTES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))){
			// 县区局
			queryWrapperStationinfo.eq(GasStationinfoEntity::getType, "group");
			queryWrapperStationinfo.eq(GasStationinfoEntity::getIsAnalyse, "Y");
			queryWrapperStationinfo.eq(GasStationinfoEntity::getTaxorgcode, currentDeptId);
		}else if(Constants.TAX_CITIES.equals(TsBqUtils.getTaxOrgLevel(currentDeptId))){
			// 市局
			queryWrapperStationinfo.eq(GasStationinfoEntity::getType, "group");
			queryWrapperStationinfo.eq(GasStationinfoEntity::getIsAnalyse, "Y");
			queryWrapperStationinfo.like(GasStationinfoEntity::getTaxorgcode, currentDeptId.substring(0,5));
			
		}else{
			// 省局
			queryWrapperStationinfo.eq(GasStationinfoEntity::getType, "group");
			queryWrapperStationinfo.eq(GasStationinfoEntity::getIsAnalyse, "Y");
		}
		
		List<GasStationinfoEntity> listGasStationinfo = gasStationinfoService.list(queryWrapperStationinfo);
		List<String> stationinfoIdList = new ArrayList<>();
		for (GasStationinfoEntity stationinfo : listGasStationinfo) {
			String stationinfoId = stationinfo.getId();
			stationinfoIdList.add(stationinfoId);
		}
		// 查询加油站下面的摄像头
		// LambdaQueryWrapper<GasStationinfoEntity> queryWrapperCam = Wrappers.lambdaQuery();
		// queryWrapperCam.in(GasStationinfoEntity::getPid, stationinfoIdList);
		// queryWrapperCam.eq(GasStationinfoEntity::getType, "cam");
		// List<GasStationinfoEntity> camList = gasStationinfoService.list(queryWrapperCam);
		// List<String> camIdList = new ArrayList<>();
		// for (GasStationinfoEntity caminfo : camList) {
		// 	String id = caminfo.getId();
		// 	camIdList.add(id);
		// }
		
		// 查询区域 server_area
		// LambdaQueryWrapper<GasServerAreaEntity> areaQueryWrapper = Wrappers.lambdaQuery();
		// areaQueryWrapper.in(GasServerAreaEntity::getCamid, camIdList);
		// List<GasServerAreaEntity> serverAreaList = gasServerAreaService.list(areaQueryWrapper);
		
		// List<String> areaNumberList = new ArrayList<>();
		// List<String> serverChannelList = new ArrayList<>();
		// List<String> serverIdList = new ArrayList<>();
		
		// for (GasServerAreaEntity serverArea : serverAreaList) {
		// 	String areaNumber = serverArea.getAreaNumber();
		// 	String serverChannel = serverArea.getServerChannel();
		// 	String serverId = serverArea.getServerId();
			
		// 	areaNumberList.add(areaNumber);
		// 	serverChannelList.add(serverChannel);
		// 	serverIdList.add(serverId);
		// }
		
		// 查询渠道 server
		// LambdaQueryWrapper<GasServerChannelEntity> serverQueryWrapper = Wrappers.lambdaQuery();
		// serverQueryWrapper.in(GasServerChannelEntity::getId, serverIdList);
		// List<GasServerChannelEntity> serverList = gasServerChannelService.list(serverQueryWrapper);
		// List<String> listTopic = new ArrayList<>();
		// for (GasServerChannelEntity server : serverList) {
		// 	String topic = server.getTopic();
		// 	listTopic.add(topic);
			
		// }
		
		
		if(TsBqUtils.isNotNull(stationinfoIdList)){
			Page page = new Page(gasStaytimeResult.getPage(), gasStaytimeResult.getLimit());
			LambdaQueryWrapper<GasStaytimeResultEntity> queryWrapper = Wrappers.lambdaQuery();
			// 查询条件示例
			String messageMsegtype = gasStaytimeResult.getMessageMsegtype();

			if (!TsBqUtils.isNull(gasStaytimeResult.getCreateTimeStart())) {
				// queryWrapper.ge(GasStaytimeResultEntity::getMessageDisappear, sdf.parse(gasStaytimeResult.getCreateTimeStart()));
				queryWrapper.ge(GasStaytimeResultEntity::getMessageDisappear,
						sdf.parse(gasStaytimeResult.getCreateTimeStart() + " 00:00:00"));
			}
			if (!TsBqUtils.isNull(gasStaytimeResult.getCreateTimeEnd())) {
				// queryWrapper.le(GasStaytimeResultEntity::getMessageDisappear, sdf.parse(gasStaytimeResult.getCreateTimeEnd()));
				queryWrapper.le(GasStaytimeResultEntity::getMessageDisappear,
						sdf.parse(gasStaytimeResult.getCreateTimeEnd() + " 23:59:59"));
			}

			if (!StringUtils.isEmpty(messageMsegtype)) {
				queryWrapper.eq(GasStaytimeResultEntity::getMessageMsegtype, messageMsegtype);
			}
			
			// queryWrapper.in(GasStaytimeResultEntity::getFromTopic,listTopic);
			queryWrapper.in(GasStaytimeResultEntity::getStationId,stationinfoIdList);
			
			
			LocalDate today = LocalDate.now();
		    LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth());
		    LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
			
			queryWrapper.ge(GasStaytimeResultEntity::getMessageDisappear,
						sdf.parse(firstDayOfMonth.toString() + " 00:00:00"));
			
			queryWrapper.le(GasStaytimeResultEntity::getMessageDisappear,
						sdf.parse(lastDayOfMonth.toString() + " 23:59:59"));
			
			queryWrapper.orderByDesc(GasStaytimeResultEntity::getMessageDisappear);
			IPage<GasStaytimeResultEntity> iPage = gasStaytimeResultService.page(page, queryWrapper);
			
			List<GasStaytimeResultEntity> records = iPage.getRecords();
			
			for (GasStaytimeResultEntity staytime : records) {
				
				GasStationinfoEntity gasStationinfo = gasStationinfoService.getById(staytime.getStationId());
				
				staytime.setStation(TsBqUtils.handleEndBeforeParentheses(gasStationinfo.getName()));
				
				
				/*String messageChannel = staytime.getMessageChannel();
				String messageAreanumber = staytime.getMessageAreanumber();
				
				String fromTopic = staytime.getFromTopic();
				
				LambdaQueryWrapper<GasServerChannelEntity> serverChannelQueryWrapper = Wrappers.lambdaQuery();
				
				serverChannelQueryWrapper.eq(GasServerChannelEntity::getTopic, fromTopic);
				
				
				List<GasServerChannelEntity> gasServerChannelList = gasServerChannelService.list(serverChannelQueryWrapper);
				
				if(TsBqUtils.isNotNull(gasServerChannelList)){
					
					GasServerChannelEntity serverChannel = gasServerChannelList.get(0);
					String gasServerId = serverChannel.getId();
					
					LambdaQueryWrapper<GasServerAreaEntity> serverAreaQueryWrapper = Wrappers.lambdaQuery();
					
					serverAreaQueryWrapper.eq(GasServerAreaEntity::getServerChannel, messageChannel);
					serverAreaQueryWrapper.eq(GasServerAreaEntity::getAreaNumber, messageAreanumber);
					serverAreaQueryWrapper.eq(GasServerAreaEntity::getServerId, gasServerId);
					
					List<GasServerAreaEntity> list = gasServerAreaService.list(serverAreaQueryWrapper);
					
					if(TsBqUtils.isNotNull(list)){
						GasServerAreaEntity gasServerAreaEntity = list.get(0);
						String camid = gasServerAreaEntity.getCamid();
						if(TsBqUtils.isNotNull(camid)){
							GasStationinfoEntity stationinfo = gasStationinfoService.getById(camid);
							if(TsBqUtils.isNotNull(stationinfo)){
								String pid = stationinfo.getPid();
								GasStationinfoEntity stationinfo1 = gasStationinfoService.getById(pid);
								if(TsBqUtils.isNotNull(stationinfo1)){
									
									staytime.setStation(TsBqUtils.handleEndBeforeParentheses(stationinfo1.getName()));
								}else{
									staytime.setStation("未匹配到加油站(stationinfo1)");
								}
							}else{
								staytime.setStation("未匹配到加油站(stationinfo)");
							}
						}else{
							staytime.setStation("未匹配到加油站(camid)");
						}
					}else{
						
						staytime.setStation("未匹配到加油站(GasServerArea)");
					}
					
				}else{
					staytime.setStation("未匹配到加油站(GasServer)");
					
				}*/
				
			}
			
			return DataResult.success(iPage);
		}else{
			return DataResult.fail("暂无加油站数据");
		}
		
	}
	
	
	@ApiOperation(value = "停留时间按年月分组")
	@PostMapping("/staytimeGroupYearMonth")
	@ResponseBody
	public DataResult staytimeGroupYearMonth() {
		
		
		Date date = new Date();
        String currentDeptId = httpSessionService.getCurrentDeptId();
        
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        String currentYear = sdf.format(date);
        GasAnalyseRegionRankingEntity gasAnalyseRegionRanking = new GasAnalyseRegionRankingEntity();
        
        gasAnalyseRegionRanking.setYearMonths(currentYear);
        
        String taxOrgLevel = TsBqUtils.getTaxOrgLevel(currentDeptId);
		String substring = "";
		if(Constants.TAX_COUNTES.equals(taxOrgLevel)){
			// 县区局
			substring = currentDeptId.substring(0,7);
		}else if(Constants.TAX_CITIES.equals(taxOrgLevel)){
			// 市局
			substring = currentDeptId.substring(0,5);
		}else{
			// 省局
		}
		
        gasAnalyseRegionRanking.setTaxorgcode(substring);
        
		GasAnalyseRegionRankingEntity gasolineEntity = gasAnalyseRegionRankingService.groupYearMonthAmountGasoline(gasAnalyseRegionRanking);
		GasAnalyseRegionRankingEntity dieselEntity = gasAnalyseRegionRankingService.groupYearMonthAmountDiesel(gasAnalyseRegionRanking);

		
		List<Object> list = new ArrayList<>();
		List<String> gasolineCarList = new ArrayList<>();
		
		if (TsBqUtils.isNotNull(gasolineEntity)) {
			gasolineCarList.add(gasolineEntity.getMonth1());
			gasolineCarList.add(gasolineEntity.getMonth2());
			gasolineCarList.add(gasolineEntity.getMonth3());
			gasolineCarList.add(gasolineEntity.getMonth4());
			gasolineCarList.add(gasolineEntity.getMonth5());
			gasolineCarList.add(gasolineEntity.getMonth6());
			gasolineCarList.add(gasolineEntity.getMonth7());
			gasolineCarList.add(gasolineEntity.getMonth8());
			gasolineCarList.add(gasolineEntity.getMonth9());
			gasolineCarList.add(gasolineEntity.getMonth10());
			gasolineCarList.add(gasolineEntity.getMonth11());
			gasolineCarList.add(gasolineEntity.getMonth12());
			
		}
		
		List<String> dieselCarList = new ArrayList<>();
		
		if (TsBqUtils.isNotNull(dieselEntity)) {
			dieselCarList.add(dieselEntity.getMonth1());
			dieselCarList.add(dieselEntity.getMonth2());
			dieselCarList.add(dieselEntity.getMonth3());
			dieselCarList.add(dieselEntity.getMonth4());
			dieselCarList.add(dieselEntity.getMonth5());
			dieselCarList.add(dieselEntity.getMonth6());
			dieselCarList.add(dieselEntity.getMonth7());
			dieselCarList.add(dieselEntity.getMonth8());
			dieselCarList.add(dieselEntity.getMonth9());
			dieselCarList.add(dieselEntity.getMonth10());
			dieselCarList.add(dieselEntity.getMonth11());
			dieselCarList.add(dieselEntity.getMonth12());
			
		}

		List<String> monthList = new ArrayList<>();
		monthList.add("1月");
		monthList.add("2月");
		monthList.add("3月");
		monthList.add("4月");
		monthList.add("5月");
		monthList.add("6月");
		monthList.add("7月");
		monthList.add("8月");
		monthList.add("9月");
		monthList.add("10月");
		monthList.add("11月");
		monthList.add("12月");
		
		list.add(gasolineCarList);
		list.add(dieselCarList);
		
		list.add(monthList);
		list.add("加油站流量统计");
		return DataResult.success(list);
	}
	
	@ApiOperation(value = "销售额统计按年月分组")
	@PostMapping("/saleGroupYearMonth")
	@ResponseBody
	public DataResult saleGroupYearMonth() {
		
		Date date = new Date();
        String currentDeptId = httpSessionService.getCurrentDeptId();
        
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        String currentYear = sdf.format(date);
        GasAnalyseRegionRankingEntity gasAnalyseRegionRanking = new GasAnalyseRegionRankingEntity();
        
        gasAnalyseRegionRanking.setYearMonths(currentYear);
        
        String taxOrgLevel = TsBqUtils.getTaxOrgLevel(currentDeptId);
		String substring = "";
		if(Constants.TAX_COUNTES.equals(taxOrgLevel)){
			// 县区局
			substring = currentDeptId.substring(0,7);
		}else if(Constants.TAX_CITIES.equals(taxOrgLevel)){
			// 市局
			substring = currentDeptId.substring(0,5);
		}else{
			// 省局
		}
		
        gasAnalyseRegionRanking.setTaxorgcode(substring);
        
		GasAnalyseRegionRankingEntity regionRanking = gasAnalyseRegionRankingService.groupYearMonth(gasAnalyseRegionRanking);

		List<Object> list = new ArrayList<>();

		List<String> regionRankingList = new ArrayList<>();
		if (TsBqUtils.isNotNull(regionRanking)) {
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth1()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth2()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth3()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth4()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth5()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth6()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth7()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth8()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth9()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth10()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth11()));
			regionRankingList.add(TsBqUtils.roundItUp(regionRanking.getMonth12()));
			
		}

		List<String> monthList = new ArrayList<>();
		monthList.add("1月");
		monthList.add("2月");
		monthList.add("3月");
		monthList.add("4月");
		monthList.add("5月");
		monthList.add("6月");
		monthList.add("7月");
		monthList.add("8月");
		monthList.add("9月");
		monthList.add("10月");
		monthList.add("11月");
		monthList.add("12月");
		
		list.add(regionRankingList);
		list.add(monthList);
		list.add("销售额统计");
		
		return DataResult.success(list);
		
	}
	
	@ApiOperation(value = "申报额统计按年月分组")
	@PostMapping("/declaretaxGroupYearMonth")
	@ResponseBody
	public DataResult declaretaxGroupYearMonth() {
		
		String currentDeptId = httpSessionService.getCurrentDeptId();
		String taxOrgLevel = TsBqUtils.getTaxOrgLevel(currentDeptId);
		String substring = "";
		if(Constants.TAX_COUNTES.equals(taxOrgLevel)){
			// 县区局
			substring = currentDeptId.substring(0,7);
		}else if(Constants.TAX_CITIES.equals(taxOrgLevel)){
			// 市局
			substring = currentDeptId.substring(0,5);
		}else{
			// 省局
		}
		
		GasDeclaretaxEntity gasDeclaretaxEntity = gasDeclaretaxService.groupYearMonth(substring);

		List<Object> list = new ArrayList<>();

		List<String> gasDeclaretaxList = new ArrayList<>();
		if (TsBqUtils.isNotNull(gasDeclaretaxEntity)) {
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth1()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth2()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth3()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth4()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth5()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth6()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth7()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth8()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth9()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth10()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth11()));
			gasDeclaretaxList.add(TsBqUtils.roundItUp(gasDeclaretaxEntity.getMonth12()));
			
		}

		List<String> monthList = new ArrayList<>();
		monthList.add("1月");
		monthList.add("2月");
		monthList.add("3月");
		monthList.add("4月");
		monthList.add("5月");
		monthList.add("6月");
		monthList.add("7月");
		monthList.add("8月");
		monthList.add("9月");
		monthList.add("10月");
		monthList.add("11月");
		monthList.add("12月");
		list.add(gasDeclaretaxList);
		
		list.add(monthList);
		list.add("申报额统计");
		return DataResult.success(list);
	}
	
	private static String handleMonthYear(int month, int year) {
		if (month <= 9) {
			return year + "0" + month;
		} else {
			return year + "" + month;
		}
	}
	
}
